package com.dc.bobaoge.project.v2.to.v3.business.core;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dc.bobaoge.base.entity.core.po.Title;
import com.dc.bobaoge.base.mapper.core.TitleMapper;
import com.dc.bobaoge.project.base.core.old.mapper.OldCoreMessageTypeMapper;
import com.own.business.sync.trigger.base.entity.SyncTrigger;
import com.own.business.sync.trigger.base.method.ResolveMethod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * MessageResolveMethod
 *
 * @author chenxueli
 * @date 2023-12-22 11:00:00
 */
@Slf4j
@Component
public class TitleResolveMethod implements ResolveMethod {

    @Resource
    private OldCoreMessageTypeMapper oldCoreMessageTypeMapper;

    @Resource
    private TitleMapper titleMapper;

    /**
     * 修改的处理方法
     *
     * @param trigger 日志信息
     */
    @Override
    public void update(SyncTrigger trigger) {
        // 查询原有的标题信息
        var messageType = oldCoreMessageTypeMapper.selectById(trigger.getTargetId());
        var wrapper = new LambdaUpdateWrapper<Title>()
                .eq(Title::getId, trigger.getTargetId())
                .set(Title::getName, messageType.getMsgTypeName());
        titleMapper.update(wrapper);
    }

    /**
     * 名称信息
     *
     * @return 名称
     */
    @Override
    public String name() {
        return "title";
    }

}
